package subject_set.lc200;

import java.util.LinkedList;
import java.util.List;

/**
 * @author haomin
 * @date 2022/12/24 23:08
 **/
public class Num23 {
    class Solution {
        public ListNode mergeKLists(ListNode[] lists) {
            if(lists.length == 0) return null;
            for(int i = 1; i < lists.length; ++i) {
                lists[i] = conbin(lists[i-1], lists[i]);
            }
            return lists[lists.length - 1];
        }
        public ListNode conbin(ListNode n1, ListNode n2) {
            if(n1 == null) return n2;
            if(n2 == null) return n1;

            if(n1.val < n2.val) {
                n1.next = conbin(n1.next, n2);
                return n1;
            }else {
                n2.next = conbin(n1, n2.next);
                return n2;
            }
        }
    }
}